package com.yand.thread.Future;

import java.util.concurrent.*;

public class NettyTest {

    public static void main(String[] args) {

        //实现一个Callable接口
        Callable<String> c = new Callable<String>() {

            @Override
            public String call() throws Exception {

                //这里是你的业务逻辑处理
                 System.out.println(123212321);
                //让当前线程阻塞1秒看下效果
                Thread.sleep(10000);
                return "asdsa";
            }
        };
        FutureTask futureTask = new FutureTask(c);
        ExecutorService es = Executors.newFixedThreadPool(2);
        Future<String> fn = null;
        for(int i =0 ; i < 2; i ++){
            //记得要用submit，执行Callable对象
            fn = es.submit(c);
        }

        //一定要调用这个方法，不然executorService.isTerminated()永远不为true
        es.shutdown();

        //无限循环等待任务处理完毕  如果已经处理完毕 isDone返回true
      //  while (!fn.isDone()) {
            try {
                //处理完毕后返回的结果
                System.out.println(fn.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
      //  }
    }

    static class Netty {

        private String name;

        private Netty(String name) {
            this.name = name;
        }


    }

}
